﻿using System.Collections.Generic;

namespace xsb.core
{
    class Data
    {
        /*
         * 核心数据结构
         */
        public class Person
        {
            //学号
            public string id { set; get; }
            //姓名
            public string name { set; get; }
            //性别
            public bool is_male { set; get; }
            //学院
            public string college { set; get; }
            //是否是种子选手
            public bool seed { set; get; }

        }

        public class Group
        {
            //种子选手数量
            public int seed_num_male { set;  get; }
            public int seed_num_female { set; get; }
            //成员列表
            public List<Person> members { get; }
            public int male_num { set; get; }
            public int female_num { set; get; }
            //每个学院的成员数
            //保留get供遍历
            public Dictionary<string, int> college_num { get; }
            //预留的分数位，在分配女生时可能用到
            public int rank { set; get; }

            public Group()
            {
                members = new List<Person>();
                college_num = new Dictionary<string, int>();
            }

            public void addMember(Person person)
            {
                members.Add(person);
                if (college_num.ContainsKey(person.college))
                    college_num[person.college]++; 
                else
                    college_num.Add(person.college, 1);

                if (person.is_male)
                {
                    male_num++;
                    if (person.seed)
                        seed_num_male++;
                } else
                {
                    female_num++;
                    if (person.seed)
                        seed_num_female++;
                }
            }

            public void removeMember(Person person)
            {
                members.Remove(person);
                college_num[person.college]--;

                if (person.is_male)
                {
                    male_num--;
                    if (person.seed)
                        seed_num_male--;
                }
                else
                {
                    female_num--;
                    if (person.seed)
                        seed_num_female--;
                }
            }

            public void removeMember(int index)
            {
                removeMember(members[index]);
            }

            public int getCountOfTargetCollege(string college)
            {
                if (college_num.ContainsKey(college))
                    return college_num[college];

                return 0;
            }

            public int getSeedNum()
            {
                return seed_num_female + seed_num_male;
            }
        }

        public static List<Person> all_person;
    }
}
